import { getGiveRecordDetail } from "@src/api/member";
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import base from "@src/store/base";

Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: base,
    fields: ['themeColor', 'themeTitleColor'],
  }],
  data: {
    receiveCode: null
  },
  methods: {
    onLoad(options) {
      this.setData({ receiveCode: options.receiveCode })
    },
    onLogin() {
      this.fetchData();
    },
    fetchData() {
      let data = { receiveCode: this.data.receiveCode }
      getGiveRecordDetail(data).then(res => {
        if (res.code === 0) {
          this.setData({ giveRecordDetailData: res.data });
        }
      })
    },
    handleToShare() {
      this.selectComponent("#share-dialog").open();
    },
    handleFullPoster(e) {
      this.setData({ fullShareImg: e.detail.shareImg })
    },
    handleSimplePoster(e) {
      this.setData({ simpleShareImg: e.detail.shareImg })
    },
    handleShowMomentsPost() {
      wx.previewImage({
        urls: [this.data.fullShareImg], // 需要预览的图片http链接列表
        success: e => {
          console.log(e);
        }
      });
    },
    onShareAppMessage(res) {
      this.selectComponent("#share-dialog").close();
      return {
        title: `送你一张会员卡（${this.data.giveRecordDetailData.categoryName}），点击消息立即领取。`,
        path: `pages/sendCard/main?scene=${this.data.giveRecordDetailData.receiveCode}&receiveWay=2`,
        desc: "",
        imageUrl: this.data.simpleShareImg
      };
    }
  }
})
